﻿using AppDesigner.DragDropEx;
using AppDesigner.File;
using AppDesigner.Model;
using AppDesigner.Shared;
using AppDesigner.XmlParser;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Controls;
using System.Xml;

namespace AppDesigner.ViewModel
{
    public class ToolBoxViewModel : BindableViewModel,IDragSource
    {
        #region Fields

        private ObservableCollection<ControlNode> _controls = new ObservableCollection<ControlNode>();
        private ControlNode _selectedControl;

        #endregion

        public ToolBoxViewModel()
        {
            LoadControls();
        }

        private void LoadControls()
        {
            //TODO 这个地方最终应该是读取配置文件中的信息
            Controls.Add(new ControlNode("Grid", "网格布局", "/Images/ControlAssets/builder_component_grid.png", typeof(Grid)));
            //ControlInfos.Add(new ControlInfo("Grid", "Grid", "线性布局面板", "/Images/ControlAssets/builder_component_button.png"));
            //ControlInfos.Add(new ControlInfo("Grid", "Grid", "绝对布局面板", "/Images/ControlAssets/builder_component_checkbox.png"));
            Controls.Add(new ControlNode("List", "数据列表", "/Images/ControlAssets/builder_component_listview.png", typeof(ListBox)));
            Controls.Add(new ControlNode("Tab", "选项卡", "/Images/ControlAssets/builder_component_tab_bar.png", typeof(TabControl)));
            Controls.Add(new ControlNode("Text", "标签", "/Images/ControlAssets/builder_component_textblock.png", typeof(TextBlock)));
            Controls.Add(new ControlNode("TextInput", "文本输入框", "/Images/ControlAssets/builder_component_text_input.png", typeof(TextBox)));
            Controls.Add(new ControlNode("RadioButton", "单选框", "/Images/ControlAssets/builder_component_radio.png", typeof(RadioButton)));
            Controls.Add(new ControlNode("CheckBox", "复选框", "/Images/ControlAssets/builder_component_checkbox.png", typeof(CheckBox)));
            Controls.Add(new ControlNode("Image", "图片", "/Images/ControlAssets/builder_component_image.png", typeof(Image)));
            Controls.Add(new ControlNode("Button", "按钮", "/Images/ControlAssets/builder_component_button.png", typeof(Button)));
        }
       
        #region Properties

        public ObservableCollection<ControlNode> Controls
        {
            get { return _controls; }
            set
            {
                SetProperty(ref _controls, value, () => this.Controls);
            }
        }

        public ControlNode SelectedControl
        {
            get { return _selectedControl; }
            set { _selectedControl = value; }
        }

        #endregion

        public void StartDrag(DragDropInfo dragDropInfo)
        {
            if (SelectedControl != null)
            {
                dragDropInfo.SetDragDropData(SelectedControl);
            }
        }

        private void PrepareTool(ControlNode node, bool drag)
        {

        }
    }
}
